package com.shop2cn.iapi.sqoptrade.parameter.model.placeorder;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.shop2cn.iapi.sqoptrade.parameter.enums.LogisticsTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderVo;
import com.ymttest.database.sharding.db.sharding.model.OrderCouponDetailPo;
import com.ymttest.database.sharding.db.sharding.model.ShenqiProxyChainPo;

/**
 */
public class Order {

	// 订单ID
	private long orderId;

	// 卖家ID
	private long sellerId;

	private long hunterId;

	private int hunterOrderType;

	private OrderVo orderVo;

	private BigDecimal freight;

	private BigDecimal payableAmount;

	// 该订单使用的商家优惠券码
	private String sellerCouponCode;

	// 该订单分摊到的商家优惠券面值
	private BigDecimal sellerCouponValue = BigDecimal.ZERO;

	// 该订单使用的平台优惠券码
	private String ymatouCouponCode;

	// 该订单分摊到的平台优惠券面值
	private BigDecimal ymatouCouponValue = BigDecimal.ZERO;
	
	// 优惠券/码
	private int couponMainType;
	
	// 该订单分摊到的返点金额
	private BigDecimal rebateAmountValue = BigDecimal.ZERO;

	// 订单上商品总成交价
	private BigDecimal totalProductPrice = BigDecimal.ZERO;

	// 使用了商家优惠券的总成交价
	private BigDecimal totalProductPriceInSellerCoupon = BigDecimal.ZERO;

	// 享受的商家优惠金额
	private BigDecimal sellerPromotionAmount = BigDecimal.ZERO;

	// 订单里各订单项关于运费的权重
	private List<BigDecimal> orderItemWeightsOnFreight = new ArrayList<BigDecimal>();

	// 订单里各订单项关于商家优惠券的权重
	private List<BigDecimal> orderItemWeightsOnSellerCoupon = new ArrayList<BigDecimal>();

	// 订单里各订单项关于平台优惠券的权重
	private List<BigDecimal> orderItemWeightsOnYmatouCoupon = new ArrayList<BigDecimal>();

	// 订单里各订单项关于返点金额的权重
	private List<BigDecimal> orderItemWeightsOnRebateAmount = new ArrayList<BigDecimal>();
	
	private BigDecimal cardAmount = BigDecimal.ZERO;

	// 订单里各订单项关于折扣的权重
	private List<BigDecimal> orderItemWeightsOnDiscount = new ArrayList<BigDecimal>();
	
	// 订单里各订单项关于积分抵扣金额的权重
	private List<BigDecimal> orderItemWeightsOnIntegralDeduction = new ArrayList<BigDecimal>();
	
	// 订单里各订单项关于积分的权重
	private List<BigDecimal> orderItemWeightsOnIntegral = new ArrayList<BigDecimal>();
	
	// 订单里各订单项关于区域折扣的权重
	private List<BigDecimal> orderItemWeightsOnRegionDiscount = new ArrayList<BigDecimal>();

	// 订单里的商品项
	private List<OrderItem> orderItems = new ArrayList<OrderItem>();

	// 该订单分摊到的折扣面值
	private BigDecimal orderDiscount = BigDecimal.ZERO;
	
	// 该订单分摊到的积分抵扣金额
	private BigDecimal orderIntegralDeduction = BigDecimal.ZERO;
	
	// 该订单分摊到的区域折扣
	private BigDecimal regionDiscountValue = BigDecimal.ZERO;
	
	// 该订单分摊到的积分
	private Long orderIntegral = 0L;
	
	private Boolean isProxy = false;
	
	private Boolean isInherited = false;
	
	private Boolean isPlatformSupplierOrder = false;
	
	// 订单的毛利润
	private BigDecimal orderGrossProfit;

	private long goodsOwnerId;

	private int shenqiLogisticsType;

	private int shenqiIdCardRequirement;

	private String currency;

	private String currencySymbol;

	private String deviceId;

	private String equipmentId;

	private String sourceIp;

	private BigDecimal taxFee;
	
	private Boolean AfterAcctivityFinishAccept;
	
	// 卖家优惠券来源：0/null：越洋电铺，1：中免大会员
	private Integer sellerCouponSource;

	// 卖家券类型：0/null：满减券，1：满折券，2：代金券
	private Integer sellerCouponType;
	
	private Long salesman;
	
	private List<OrderCouponDetailPo> orderCouponDetailList;

	public List<OrderItem> getOrderItems() {
		return orderItems;
	}

	public long getHunterId() {
		return hunterId;
	}

	public void setHunterId(long hunterId) {
		this.hunterId = hunterId;
	}

	public int getHunterOrderType() {
		return hunterOrderType;
	}

	public void setHunterOrderType(int hunterOrderType) {
		this.hunterOrderType = hunterOrderType;
	}

	public void setOrderItems(List<OrderItem> orderItems) {
		this.orderItems = orderItems;
	}

	public long getOrderId() {
		return orderId;
	}

	public BigDecimal getCardAmount() {
		return cardAmount;
	}

	public void setCardAmount(BigDecimal cardAmount) {
		this.cardAmount = cardAmount;
	}

	public void setOrderId(long orderId) {
		this.orderId = orderId;
	}

	public long getSellerId() {
		return sellerId;
	}

	public void setSellerId(long sellerId) {
		this.sellerId = sellerId;
	}

	public String getSellerCouponCode() {
		return sellerCouponCode;
	}

	public void setSellerCouponCode(String sellerCouponCode) {
		this.sellerCouponCode = sellerCouponCode;
	}

	public BigDecimal getSellerCouponValue() {
		return sellerCouponValue;
	}

	public void setSellerCouponValue(BigDecimal sellerCouponValue) {
		this.sellerCouponValue = sellerCouponValue;
	}

	public String getYmatouCouponCode() {
		return ymatouCouponCode;
	}

	public void setYmatouCouponCode(String ymatouCouponCode) {
		this.ymatouCouponCode = ymatouCouponCode;
	}

	public BigDecimal getYmatouCouponValue() {
		return ymatouCouponValue;
	}

	public void setYmatouCouponValue(BigDecimal ymatouCouponValue) {
		this.ymatouCouponValue = ymatouCouponValue;
	}

	public BigDecimal getTotalProductPrice() {
		return totalProductPrice;
	}

	public void setTotalProductPrice(BigDecimal totalProductPrice) {
		this.totalProductPrice = totalProductPrice;
	}

	public BigDecimal getTotalProductPriceInSellerCoupon() {
		return totalProductPriceInSellerCoupon;
	}

	public void setTotalProductPriceInSellerCoupon(
			BigDecimal totalProductPriceInSellerCoupon) {
		this.totalProductPriceInSellerCoupon = totalProductPriceInSellerCoupon;
	}

	public BigDecimal getSellerPromotionAmount() {
		return sellerPromotionAmount;
	}

	public void setSellerPromotionAmount(BigDecimal sellerPromotionAmount) {
		this.sellerPromotionAmount = sellerPromotionAmount;
	}

	public List<BigDecimal> getOrderItemWeightsOnFreight() {
		return orderItemWeightsOnFreight;
	}

	public void setOrderItemWeightsOnFreight(
			List<BigDecimal> orderItemWeightsOnFreight) {
		this.orderItemWeightsOnFreight = orderItemWeightsOnFreight;
	}

	public List<BigDecimal> getOrderItemWeightsOnSellerCoupon() {
		return orderItemWeightsOnSellerCoupon;
	}

	public void setOrderItemWeightsOnSellerCoupon(
			List<BigDecimal> orderItemWeightsOnSellerCoupon) {
		this.orderItemWeightsOnSellerCoupon = orderItemWeightsOnSellerCoupon;
	}

	public List<BigDecimal> getOrderItemWeightsOnYmatouCoupon() {
		return orderItemWeightsOnYmatouCoupon;
	}

	public void setOrderItemWeightsOnYmatouCoupon(
			List<BigDecimal> orderItemWeightsOnYmatouCoupon) {
		this.orderItemWeightsOnYmatouCoupon = orderItemWeightsOnYmatouCoupon;
	}

	public OrderVo getOrderVo() {
		return orderVo;
	}

	public void setOrderVo(OrderVo orderVo) {
		this.orderVo = orderVo;
	}

	public BigDecimal getFreight() {
		return freight;
	}

	public void setFreight(BigDecimal freight) {
		this.freight = freight;
	}

	public BigDecimal getPayableAmount() {
		return payableAmount;
	}

	public void setPayableAmount(BigDecimal payableAmount) {
		this.payableAmount = payableAmount;
	}

	public long getGoodsOwnerId() {
		return goodsOwnerId;
	}

	public void setGoodsOwnerId(long goodsOwnerId) {
		this.goodsOwnerId = goodsOwnerId;
	}

	public int getShenqiLogisticsType() {
		return shenqiLogisticsType;
	}

	public void setShenqiLogisticsType(int shenqiLogisticsType) {
		this.shenqiLogisticsType = shenqiLogisticsType;
	}

	public int getShenqiIdCardRequirement() {
		return shenqiIdCardRequirement;
	}

	public void setShenqiIdCardRequirement(int shenqiIdCardRequirement) {
		this.shenqiIdCardRequirement = shenqiIdCardRequirement;
	}

	public boolean needsUploadIdCard(boolean checkSignedBAOMI) {
		return LogisticsTypeEnum.SailProtect == orderVo.getLogisticsType()
				|| LogisticsTypeEnum.XloboBondedDelivery == orderVo
						.getLogisticsType()
				|| LogisticsTypeEnum.BondedDelivery == orderVo
						.getLogisticsType()
				|| (LogisticsTypeEnum.US == orderVo.getLogisticsType() && checkSignedBAOMI);
	}

	public BigDecimal getOrderDiscount() {
		return orderDiscount;
	}

	public void setOrderDiscount(BigDecimal orderDiscount) {
		this.orderDiscount = orderDiscount;
	}

	public List<BigDecimal> getOrderItemWeightsOnDiscount() {
		return orderItemWeightsOnDiscount;
	}

	public void setOrderItemWeightsOnDiscount(
			List<BigDecimal> orderItemWeightsOnDiscount) {
		this.orderItemWeightsOnDiscount = orderItemWeightsOnDiscount;
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public String getCurrencySymbol() {
		return currencySymbol;
	}

	public void setCurrencySymbol(String currencySymbol) {
		this.currencySymbol = currencySymbol;
	}

	/**
	 * 订单剩余最大可优惠金额
	 *
	 * @return
	 */
	public BigDecimal calcMaxPromotionLeft() {
		BigDecimal result = getTotalProductPrice()
				.subtract(new BigDecimal("0.01"))
				// 每个订单，用户至少需要付1分钱
				.subtract(Utils.zeroIfNull(ymatouCouponValue))
				.subtract(Utils.zeroIfNull(sellerCouponValue))
				.subtract(Utils.zeroIfNull(sellerPromotionAmount));
		if (result.compareTo(BigDecimal.ZERO) < 0) {
			return BigDecimal.ZERO;
		}
		return result;
	}

	/**
	 * 订单剩余最大可优惠金额
	 *
	 * @return
	 */
	public BigDecimal calcMaxPromotionLeftAndFreight() {
		BigDecimal result = getTotalProductPrice().add(freight)
				.subtract(new BigDecimal("0.01"))
				// 每个订单，用户至少需要付1分钱
				.subtract(Utils.zeroIfNull(ymatouCouponValue))
				.subtract(Utils.zeroIfNull(sellerCouponValue))
				.subtract(Utils.zeroIfNull(sellerPromotionAmount));
		if (result.compareTo(BigDecimal.ZERO) < 0) {
			return BigDecimal.ZERO;
		}
		return result;
	}

	public String getDeviceId() {
		return deviceId;
	}

	public void setDeviceId(String deviceId) {
		this.deviceId = deviceId;
	}

	public String getEquipmentId() {
		return equipmentId;
	}

	public void setEquipmentId(String equipmentId) {
		this.equipmentId = equipmentId;
	}

	public String getSourceIp() {
		return sourceIp;
	}

	public void setSourceIp(String sourceIp) {
		this.sourceIp = sourceIp;
	}

	public boolean containsPreSalePrds() {
		return orderVo.getOrderItems().stream().anyMatch(oi -> oi.isPreSale());
	}

	public BigDecimal getTaxFee() {
		return taxFee;
	}

	public void setTaxFee(BigDecimal taxFee) {
		this.taxFee = taxFee;
	}

	public List<BigDecimal> getOrderItemWeightsOnRebateAmount() {
		return orderItemWeightsOnRebateAmount;
	}

	public void setOrderItemWeightsOnRebateAmount(
			List<BigDecimal> orderItemWeightsOnRebateAmount) {
		this.orderItemWeightsOnRebateAmount = orderItemWeightsOnRebateAmount;
	}

	public BigDecimal getRebateAmountValue() {
		return rebateAmountValue;
	}

	public void setRebateAmountValue(BigDecimal rebateAmountValue) {
		this.rebateAmountValue = rebateAmountValue;
	}

	public Boolean getAfterAcctivityFinishAccept() {
		return AfterAcctivityFinishAccept;
	}

	public void setAfterAcctivityFinishAccept(Boolean afterAcctivityFinishAccept) {
		AfterAcctivityFinishAccept = afterAcctivityFinishAccept;
	}

	public List<BigDecimal> getOrderItemWeightsOnIntegralDeduction() {
		return orderItemWeightsOnIntegralDeduction;
	}

	public void setOrderItemWeightsOnIntegralDeduction(
			List<BigDecimal> orderItemWeightsOnIntegralDeduction) {
		this.orderItemWeightsOnIntegralDeduction = orderItemWeightsOnIntegralDeduction;
	}

	public BigDecimal getOrderIntegralDeduction() {
		return orderIntegralDeduction;
	}

	public void setOrderIntegralDeduction(BigDecimal orderIntegralDeduction) {
		this.orderIntegralDeduction = orderIntegralDeduction;
	}

	public Long getOrderIntegral() {
		return orderIntegral;
	}

	public void setOrderIntegral(Long orderIntegral) {
		this.orderIntegral = orderIntegral;
	}

	public List<BigDecimal> getOrderItemWeightsOnIntegral() {
		return orderItemWeightsOnIntegral;
	}

	public void setOrderItemWeightsOnIntegral(
			List<BigDecimal> orderItemWeightsOnIntegral) {
		this.orderItemWeightsOnIntegral = orderItemWeightsOnIntegral;
	}

	public BigDecimal getOrderGrossProfit() {
		return orderGrossProfit;
	}

	public void setOrderGrossProfit(BigDecimal orderGrossProfit) {
		this.orderGrossProfit = orderGrossProfit;
	}

	public Boolean getIsProxy() {
		return isProxy;
	}

	public void setIsProxy(Boolean isProxy) {
		this.isProxy = isProxy;
	}

	public List<BigDecimal> getOrderItemWeightsOnRegionDiscount() {
		return orderItemWeightsOnRegionDiscount;
	}

	public void setOrderItemWeightsOnRegionDiscount(
			List<BigDecimal> orderItemWeightsOnRegionDiscount) {
		this.orderItemWeightsOnRegionDiscount = orderItemWeightsOnRegionDiscount;
	}

	public BigDecimal getRegionDiscountValue() {
		return regionDiscountValue;
	}

	public void setRegionDiscountValue(BigDecimal regionDiscountValue) {
		this.regionDiscountValue = regionDiscountValue;
	}

	public Integer getSellerCouponSource() {
		return sellerCouponSource;
	}

	public void setSellerCouponSource(Integer sellerCouponSource) {
		this.sellerCouponSource = sellerCouponSource;
	}

	public Integer getSellerCouponType() {
		return sellerCouponType;
	}

	public void setSellerCouponType(Integer sellerCouponType) {
		this.sellerCouponType = sellerCouponType;
	}

	public Long getSalesman() {
		return salesman;
	}

	public void setSalesman(Long salesman) {
		this.salesman = salesman;
	}

	public List<OrderCouponDetailPo> getOrderCouponDetailList() {
		return orderCouponDetailList;
	}

	public void setOrderCouponDetailList(
			List<OrderCouponDetailPo> orderCouponDetailList) {
		this.orderCouponDetailList = orderCouponDetailList;
	}

	public int getCouponMainType() {
		return couponMainType;
	}

	public void setCouponMainType(int couponMainType) {
		this.couponMainType = couponMainType;
	}

	public Boolean getIsInherited() {
		return isInherited;
	}

	public void setIsInherited(Boolean isInherited) {
		this.isInherited = isInherited;
	}

	public Boolean getIsPlatformSupplierOrder() {
		return isPlatformSupplierOrder;
	}

	public void setIsPlatformSupplierOrder(Boolean isPlatformSupplierOrder) {
		this.isPlatformSupplierOrder = isPlatformSupplierOrder;
	}
}
